/*
 * @lc app=leetcode id=260 lang=cpp
 *
 * [260] Single Number III
 */
class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {

        // find unique bit
        int x = 0, i = 0;
        for (auto n : nums) {
            x ^= n;
        }

        for (i=0; i<32; i++) {
            if (x & (1<<i)) {
                break;
            }
        }

        // divide nums with bit-i
        int a = 0, b = 0;
        uint32_t mask = 1 << i;
        for (auto n : nums) {
            if (n & mask) {
                a ^= n;
            } else {
                b ^= n;
            }
        }
        return {a,b};
        
    }
};

